Does using str in the above statement change the information in it?

A good answer might be:

No. Using the information does not change it. This is the same as with primitive variables: using them (in an arithmetic expression, say) does not change their information.

Larger Example

Here is a slightly larger version of the example program, now with a new variable of a primitive type:


class egString2
{

  public static void main ( String[] args )
  {
    String str;
    long   value;
    
    str   = new String( "The Gingham Dog" );
    value = 32912;

    System.out.println( str   );
    System.out.println( value );
  }
}

When the statement

str   = new String( "The Gingham Dog" );

is executed, a new object is created and a reference to it is placed in str. The variable str now refers to the String object.

QUESTION 7:

What happens when the statement

value = 32912;

is executed?